//
//  SearchResultViewController.m
//  ReviewDemo
//
//  Created by 苏沫离 on 2018/3/19.
//  Copyright © 2018年 long. All rights reserved.
//

#import "SearchResultViewController.h"
#import "Masonry.h"

@interface SearchResultViewController ()
<UITableViewDelegate,UITableViewDataSource>


@end

@implementation SearchResultViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat topHeight = Is_iPhoneX ? 98.0 : Is_IOS11 ? 74 : 64;
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topHeight - 1);
        make.left.bottom.right.mas_equalTo(0);
    }];
    
    [self.view addSubview:self.defaultView];
    [self.defaultView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topHeight-1);
        make.left.bottom.right.mas_equalTo(0);
    }];
    
    [self.view addSubview:self.emptyView];
    [self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topHeight-1);
        make.left.bottom.right.mas_equalTo(0);
    }];
    self.emptyView.hidden = YES;
    
    
    [self loadNetworkData];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"self,view ------ %@",self.view);

    NSLog(@"self,subviews ------ %@",self.view.subviews);

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.resultsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(UITableViewCell.class) forIndexPath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - event response

- (void)tableHeaderRightButtonClick
{
    
    
}

#pragma mark - public methods

- (void)reloadTableView
{
    if (self.resultsArray.count == 0)
    {
        self.emptyView.hidden = NO;
        self.tableView.hidden = YES;
    }
    else
    {
        self.emptyView.hidden = YES;
        self.tableView.hidden = NO;
    }
    [self.tableView reloadData];
}

#pragma mark - private methods

#pragma mark - Network Request

- (void)loadNetworkData
{
    
}

#pragma mark - setter and getters

- (NSMutableArray *)resultsArray
{
    if (_resultsArray == nil)
    {
        _resultsArray = [NSMutableArray array];
    }
    
    return  _resultsArray;
}

- (UITableView *)tableView
{
    if (_tableView == nil)
    {
        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.tableFooterView = UIView.new;
        [tableView registerClass:UITableViewCell.class forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        _tableView = tableView;
    }
    
    return _tableView;
}

- (UIView *)defaultView
{
    if (_defaultView == nil)
    {
        UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
        view.backgroundColor = Color_Purple;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.backgroundColor = Color_Purple;
        button.frame = CGRectMake(0, 0, ScreenWidth, 32);
        button.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
        [button setTitle:@"推荐标签" forState:UIControlStateNormal];
        [view addSubview:button];
        
        _defaultView = view;
    }
    
    return _defaultView;
}

- (UIView *)emptyView
{
    if (_emptyView == nil)
    {
        UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
        view.backgroundColor = [UIColor redColor];
        
        
        _emptyView = view;
    }
    
    return _emptyView;
}


@end
